using UnityEngine;

public class IndicatorMissions : MonoBehaviour
{
	public static IndicatorMissions instance;

	public GameObject timerMission;

	public GameObject targetMission;

	public int count;

	public UILabel timerLabel;

	public UILabel targetLabel;

	private UILabel labelTimer;

	private void Awake()
	{
		instance = this;
	}

	private void OnDestroy()
	{
		instance = null;
	}

	private void OnEnable()
	{
		InitMissions();
		ManagerMissions.updateTarget -= InitMissions;
		ManagerMissions.updateTarget += InitMissions;
		ManagerMissions.completeMission -= InitMissions;
		ManagerMissions.completeMission += InitMissions;
	}

	private void InitMissions()
	{
		if (!(ManagerMissions.instance == null) && ManagerMissions.currMission != null)
		{
			count = ManagerMissions.currMission.numCurStep;
			if (count < ManagerMissions.currMission.listTargetParams.Count && ManagerMissions.currMission.listTargetParams[count].showIndicator)
			{
				targetLabel.text = ManagerMissions.currMission.listTargetParams[count].curValue.ToString();
				UILabel uILabel = targetLabel;
				uILabel.text = uILabel.text + "/" + ManagerMissions.currMission.listTargetParams[count].maxValue;
				targetMission.SetActive(true);
			}
			else if (targetMission != null)
			{
				targetMission.SetActive(false);
			}
		}
	}

	private void OnDisable()
	{
		ManagerMissions.updateTarget -= InitMissions;
	}

	public void SetActiveTimer(bool val, int time = 0)
	{
		if (time > 0 && val)
		{
			timerMission.SetActive(val);
			SetTime(time);
		}
		else
		{
			timerMission.SetActive(false);
		}
	}

	public void SetTime(int timeInSec)
	{
		int num = (int)((float)timeInSec / 60f);
		int num2 = timeInSec - num * 60;
		timerMission.SetActive(true);
		timerLabel.gameObject.SetActive(true);
		timerLabel.text = ((num >= 10) ? num.ToString() : ("0" + num)) + ":" + ((num2 >= 10) ? num2.ToString() : ("0" + num2));
	}

	public static void SetVisible(bool val)
	{
		if (ManagerMissions.currMission != null && instance != null && instance.count < ManagerMissions.currMission.listTargetParams.Count)
		{
			if (ManagerMissions.currMission.listTargetParams[instance.count].showIndicator && val)
			{
				instance.targetMission.SetActive(val);
			}
			else
			{
				instance.targetMission.SetActive(false);
			}
			if (ManagerMissions.currMission.listTargetParams[instance.count].target.ShowTimer())
			{
				instance.SetActiveTimer(val);
			}
		}
	}
}
